/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Bean.Barang_Konsumen;
import Bean.Konsumen;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Yohanes Beny P
 */
@WebServlet(urlPatterns = {"/UpdatePengiriman"})
public class UpdatePengiriman extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String resi = request.getParameter("terima");

        Bean.Barang_Konsumen bk = new Barang_Konsumen();
        Bean.Konsumen ksm = new Konsumen();
        ResultSet rs1 = null;
        try {
            rs1 = ksm.cariDataKonsumen(resi);
        } catch (SQLException ex) {
            Logger.getLogger(UpdatePengiriman.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResultSet rs = null;
        try {
            rs = bk.cariData(resi);
        } catch (SQLException ex) {
            Logger.getLogger(UpdatePengiriman.class.getName()).log(Level.SEVERE, null, ex);
        }
        String noResi = null, tgl_kirim = null, tgl_terima = null, status = null, nama_peng = null, almt_peng = null, nama_pene = null, almt_pene = null;
        try {
            while (rs.next() && rs1.next()) {
                noResi = rs.getString("NO_RESI");
                tgl_kirim = rs.getString("TANGGAL_KIRIM");
                tgl_terima = rs.getString("TANGGAL_TERIMA");
                status = rs.getString("STATUS");
                nama_peng = rs1.getString("NAMA_PENGIRIM");
                nama_pene = rs1.getString("NAMA_PENERIMA");
                almt_peng = rs1.getString("ALAMAT_PENGIRIM");
                almt_pene = rs1.getString("ALAMAT_PENERIMA");
            }
        } catch (SQLException ex) {
            Logger.getLogger(UpdatePengiriman.class.getName()).log(Level.SEVERE, null, ex);
        }
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Update Pengiriman Barang</title>");
        out.println("<link href=\"css/style.css\" rel=\"stylesheet\" type=\"text/css\"/>");
        out.println("</head>");
        out.println("<body id=\"home\">");
        out.println("<div id=\"wrapper\">");
        out.println("<center>");
        out.println("</br>");
        out.println("<center><img src=\"image/header.png\" width=\"600\" height=\"100\"/></center>");
        out.println("<h1 align='right'> <a href=\"../HomeCabang.jsp\"><img src=\"image/btn_home.png\" width=\"100\" height=\"40\"/></a>");
        out.println(" <a href=\"../FilterLogout\"><img src=\"image/logout.png\" width=\"100\" height=\"40\"/></a></h1>");
        out.println("<table><form action=\"KonfirmasiUpdate\">");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">No. Resi</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\"><input type=\"hidden\" name=\"resi\" value='" + noResi + "'/>" + noResi + "</font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Nama Pengirim</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">" + nama_peng + "</font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Alamat Pengirim</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">" + almt_peng + "</font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Nama Penerima</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">" + nama_pene + "</font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Alamat Penerima</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">" + almt_pene + "</font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Status</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">" + status + "</font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Tanggal Kirim</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">" + tgl_kirim + "</font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Tanggal Terima</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\"><input type=\"date\" name=\"tgl_terima\" class=\"field1\"/></font></h3></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td align=\"left\"><h3><font color=\"black\">Ubah Status</font></h3></td>");
        out.println("<td align=\"center\" width=\"5\"><h3><font color=\"black\">:</font></h3></td>");
        out.println("<td width=\"5\"><select name=\"status\" class=\"field1\">");
        out.println("<option value=\"1\" selected=\"select\">Delivered</option>");
        out.println("<option value=\"2\" >On The Way</option>");
        out.println("<option value=\"3\" >On Transit</option>");
        out.println("<option value=\"4\" >Bad Address</option>");
        out.println("</select></td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</br></br>");
        out.println("<input type=\"submit\" name=\"submit\" value=\"Ubah Data\"/></form>");
        out.println("</center>");
        out.println("</div>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
